package com.haina.vote.service.impl;

import com.github.pagehelper.PageHelper;
import com.haina.vote.entity.KqFwModel;
import com.haina.vote.entity.KqFwPerformance;
import com.haina.vote.mapper.KqFwMapper;
import com.haina.vote.service.IKqFwService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class KqFwService implements IKqFwService {
    @Autowired
    private KqFwMapper kqFwMapper;
    //查询全部的科情服务任务单
    @Override
    public List<KqFwModel> findTask(Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<KqFwModel> kqFwModelList=kqFwMapper.findTask();
        System.out.println(kqFwModelList);
        return kqFwModelList;
    }
    //添加科情服务主表信息
    @Override
    public synchronized Integer addTask(KqFwModel kqFwModel) {
        kqFwMapper.addTask(kqFwModel);
        //返回自增的id
        Integer id=kqFwModel.getId();
        return id;
    }
    //添加科情服务的任务完成情况表
    @Override
    public int addPerformance(KqFwPerformance kqFwPerformance) {
       return kqFwMapper.addPerformance(kqFwPerformance);
    }
    //修改科情服务主表信息
    @Override
    public void updateTask(KqFwModel kqFwModel) {
        kqFwMapper.updateTask(kqFwModel);
    }
    //修改科情服务任务完成情况表
    public int updatePerformance(KqFwPerformance kqFwPerformance){
        //首先通过taskId
       return kqFwMapper.updatePerformance(kqFwPerformance);
    }
    //查询最新的一条数据
    @Override
    public KqFwModel findTaskMaxTime() {
        return kqFwMapper.findTaskMaxTime();
    }
    //修改任务单状态
    @Override
    public int setStatus(Integer id, Integer status) {
       return kqFwMapper.setStatus(id,status);
    }

    //修改反馈资料的存储路径
    @Override
    public int updateMeansUrl(KqFwModel param) {
       return kqFwMapper.updateMeansUrl(param);
    }
    //下载反馈资料
    @Override
    public KqFwModel downloadMeans(Integer id) {
        return kqFwMapper.downloadMeans(id);
    }
    //修改反馈信息
    @Override
    public int updatefeedback(KqFwModel kqFwModel) {
        return kqFwMapper.updatefeedback(kqFwModel);
    }

    @Override
    public List<KqFwModel> findTaskByName(Integer page, Integer pageSize, String tl) {
        PageHelper.startPage(page,pageSize);
        return kqFwMapper.findTaskByName(tl);
    }

    @Override
    public int deletePerformanceById(Integer id) {
        return kqFwMapper.deletePerformanceById(id);
    }

    @Override
    public int findIsExist(Integer id) {
        return kqFwMapper.findIsExist(id);
    }

    @Override
    public int findPerformanceByPid(Integer pid) {
        return kqFwMapper.findPerformanceByPid(pid);
    }

    @Override
    public int reject(Integer reject_taskId, Integer reject_taskStatus, String reject_Info) {
        return kqFwMapper.reject(reject_taskId,reject_taskStatus,reject_Info);
    }


    //删除科情服务任务单
    @Override
    public int deleteTask(Integer id) {
       //首先删除主表关联的附表中的所有项
        kqFwMapper.deletePerformance(id);
        //查询是否还存在,如果不存在关联信息即可删除主表对应记录
        List<KqFwPerformance> performanceList = kqFwMapper.findPerformanceById(id);
        int row=0;
        if (performanceList.size()==0){
            row=kqFwMapper.deleteTask(id);

        }
        return row;
    }


    //通过id查询科情服务任务单
    @Override
    public KqFwModel findTaskById(Integer id) {
        return kqFwMapper.findTaskById(id);
    }










}
